#include "Thread.h"
#include <unistd.h>
#include <iostream>
#include <memory>

using std::cout;
using std::endl;
using std::unique_ptr;

class MyThread
: public Thread
{
/* public: */
private:
    void run() override
    {
        //需要去实现具体的逻辑
        while(1)
        {
            cout << "MyThread is running!" << endl;
            sleep(1);
        }
    }
};

void test()
{
    MyThread myThread;//栈对象
    myThread.start();
    myThread.join();
    /* myThread.run();//error */
}

void test2()
{
    MyThread *pth = new MyThread(); //创建堆对象
    pth->start();
    pth->join();

    delete pth;
    pth = nullptr;
}

void test3()
{
    unique_ptr<Thread> pth1(new MyThread()); //创建堆对象
    pth1->start();
    pth1->join();
}

int main(int argc, char **argv)
{
    test3();
    return 0;
}

